package com.yanqu.collectclientdata.db.dao;

import com.yanqu.collectclientdata.controller.ClientLog;
import com.yanqu.collectclientdata.db.CollectClientDbManager;
import com.yanqu.road.dao.db.DbParameter;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author wpj
 * @Date 2020/11/30
 */
public class ClientLogDaoImpl {
    public boolean addLogBuyList(List<ClientLog> list) {
        boolean result = false;
        String sql = "INSERT INTO client_log(appId,channelId,startupID,deviceID," +
                "deviceModel,rVersion,os,osVersion," +
                "serverID,userID,openID,timestamping," +
                "loginID,pVersion,deltaTime,eventID," +
                "param,packageID) VALUES(" +
                "?,?,?,?," +
                "?,?,?,?," +
                "?,?,?,?," +
                "?,?,?,?," +
                "?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (ClientLog info : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.VARCHAR, info.getAppId()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getChannelID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getStartupID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getDeviceID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getDeviceModel()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getrVersion()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getOs()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getOsVersion()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getServerID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getUserID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getOpenID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getTimestamping()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getLoginID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getpVersion()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getDeltaTime()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getEventID()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getParam()));
            para.put(i++, new DbParameter(Types.VARCHAR, info.getPackageID()));

            mapList.add(para);
        }

        if (CollectClientDbManager.executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
